var productId;
window.onload = function (){
    //得到从前一页面提交的商品ID
    productId = getQuery("id");
    findProduct();
}

function findProduct(){
    axios.get("/goods/findById",{
        params:{
            id:productId,
        }
    }).then(resp =>{
        var info = resp.data;
        $("goodsImg").src = "/img/"+info.imgPath;
        $("nameSpan").innerHTML = info.goodsName;
        $("moneySpan").innerHTML = info.money;
        $('assessNumSpan').innerHTML = info.assessNum;

        this.fullTable(info.assessList);
    })
}

/**
 * 填充评论表格
 * @param speakList
 */
function fullTable(speakList){
    var str = "";
    speakList.forEach(n =>{
        str += `<tr><td>${n.user.minName}</td><td>${n.content}</td></tr>`;
    });
    $("data").innerHTML = str;
}

/**
 * 添加评论
 */
function add(){
    axios.get("/assess/add",{
        params:{
            productId,
            content:$("content").value
        }
    }).then(resp =>{
        fullTable(resp.data);
    });
}